package com.smzd.framework.workspace;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.smzd.framework.utils.AuthCode;
import com.smzd.utils.SessionHolder;

@Controller
public class AuthCodeController {
    @Autowired(required = false)
    private AuthCode authCode;

    @RequestMapping("/workspace/authcode")
    public void generateAuthCode(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        try {
            String authcode = authCode.generateAuthCode(request, response, 60, 20);
            SessionHolder.setObject(authCode.getSessionKey(), authcode);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
